package idbuilder

import (
	"fmt"
	"gitee.com/mjun1833/buildnotification/config"
	"sync/atomic"
)

const (
	//模板顺序为机构编码 + 子类型编码 + 时间编码 + 流水序号
	businessObjectIDTemplate = "%s%s%s%05d" //生成BusinessObjectID的模板
)

type BusinessSubType string

const (
	BusinessSubTypeDisposition             BusinessSubType = "01" //布/撤控
	BusinessSubTypeDispositionNotification BusinessSubType = "02" //告警
	BusinessSubTypeSubscribe               BusinessSubType = "03" //订阅
	BusinessSubTypeSubscribeNotification   BusinessSubType = "04" //通知
	BusinessSubTypeOther                   BusinessSubType = "99" //其他
)

var (
	businessObjectIDCounter uint32 //流水序号
)

func getBusinessObjectIDCounter() uint32 {
	return atomic.AddUint32(&businessObjectIDCounter, 1)
}

func GetBusinessObjectID(subType BusinessSubType) string {
	orgCode := config.GetInstance().GetString("PublicSecurityBureauAdministrativeCode") // 机构编码
	return fmt.Sprintf(businessObjectIDTemplate, orgCode, subType, GetNowTimeStr(), getBusinessObjectIDCounter())
}
